<?php
	error_reporting(E_ALL|E_STRICT);
	ini_set('display_errors', 1);
	date_default_timezone_set('Asia/Saigon');
	
	// directory setup and class loading
	set_include_path('.' . PATH_SEPARATOR . '../library'
		. PATH_SEPARATOR . '../application/models'
		. PATH_SEPARATOR . get_include_path());
	include "Zend/Loader.php";
	Zend_Loader::registerAutoload();
	
	
	// load configuration
	$db_config = new Zend_Config_Ini('../application/config.ini', 'database');
	$registry = Zend_Registry::getInstance();
	$registry->set('database', $db_config);
	
	$general_config = new Zend_Config_Ini('../application/config.ini', 'general');
	$registry->set('general_config', $general_config);
	
	$access_level_config = new Zend_Config_Ini('../application/config.ini', 'access_level');
	$registry->set('access_level_config', $access_level_config);
	
	$others_config = new Zend_Config_Ini('../application/config.ini', 'others');
	$registry->set('others_config', $others_config);
	
	$paging_config = new Zend_Config_Ini('../application/config.ini', 'paging');
	$registry->set('paging_config', $paging_config);
	
	$reporting_config = new Zend_Config_Ini('../application/config.ini', 'reporting');
	$registry->set('reporting_config', $reporting_config);
	
	$translate = new Zend_Translate('csv', '../application/languages/vi.csv' , 'vi', array('delimiter' => ','));
	$translate->addTranslation('../application/languages/en.csv', 'en');
	$translate->setLocale($general_config->language);
	$registry->set('Zend_Translate', $translate);	
	
	$agent_config = new Zend_Config_Ini('../application/config.ini', 'agent');
	$registry->set('agent_config', $agent_config);
	
	// setup database
	$db = Zend_Db::factory($db_config->db);
	Zend_Db_Table::setDefaultAdapter($db);
	
	// setup controller
	$frontController = Zend_Controller_Front::getInstance();
	//$frontController->throwExceptions(true);
	$frontController->setControllerDirectory('../application/controllers');
	Zend_Layout::startMvc(array('layoutPath'=>'../application/layouts'));
	
	$frontController->registerPlugin(new Vmg_Plugin_Authorization());
	
	
	//run!
	$frontController->dispatch();
	
	
